<?php
	use\ampleharvest\code\search;
	use\ampleharvest\code;

	require_once dirname(dirname(dirname(__FILE__))) . '/config/cConfig.php';
	$codeConfig = new \ampleharvest\code\cConfig();

	//require_once code\cConfig::C_STR_SOLR_PATH . '/Classes/cReaper_Solr.php';
	require_once $codeConfig->C_STR_SOLR_PATH . "/Classes/cReaper_Doc.php";
	require_once $codeConfig->C_STR_SOLR_PATH . "/Classes/Templates/Reaper_Article.php";
	//require_once dirname(dirname(__FILE__)) . "/cSolrQuery.php";
	//require_once dirname(dirname(__FILE__)) . "/User_Manager/cUserValidation.php";

	require_once dirname(__FILE__) . "/cResults.php";

	class cReaperResults extends search\cResults
	{
		public function process_Query($obj_Condition)
		{
			$str_Key = trim($obj_Condition->property);
			$str_Value = trim($obj_Condition->value);
			$str_Join = trim($obj_Condition->join);

			if (isset($obj_Condition->prefix))
			{
				$str_Value = trim($obj_Condition->prefix) . $str_Value;
			}

			switch ($str_Key)
			{
				case 'general':
					if (empty($str_Value) || $str_Value == "")
					{
						break;
					}

					$this->m_obj_Query->add_Query($str_Value);
					//add_Query($str_Query, "\"Telecommunications Board\"");
					break;
					//case cReaper_Doc::C_STR_FIELD_PUBLISH_DATE . "_end":
					//	break;
				case cReaper_Doc::C_STR_FIELD_PUBLISH_DATE . "_":
					if ((empty($str_Value) || $str_Value == "") && (empty($obj_Condition->value_end) || $obj_Condition->value_end == ""))
					{
						break;
					}
					$obj_StartDate = null;
					if (!(empty($str_Value) || $str_Value == "" || $str_Value == "*"))
					{
						$obj_StartDate = cReaperResults::convert_Date($str_Value);

						if (!$obj_StartDate)
						{
							print("The Publish Start Date you entered is invalid and will be ignored.<br/>");
							break;
						}
					}

					$obj_EndDate = null;

					if (isset($obj_Condition->value_end) && ($obj_Condition->value_end != "*"))
					{
						$obj_EndDate = cReaperResults::convert_Date(trim($obj_Condition->value_end));
						if (!$obj_EndDate)
						{
							print("The Publish End Date you entered is invalid and will be ignored.<br/>");
							break;
						}

						$obj_EndDate->setTime(23, 59, 59);
					}
					$this->m_obj_Query->add_Query_Date(cReaper_Doc::C_STR_FIELD_PUBLISH_DATE, $obj_StartDate, $obj_EndDate);
					break;
				case cReaper_Doc::C_STR_FIELD_INDEX_DATE . "_":
					if ((empty($str_Value) || $str_Value == "") && (empty($obj_Condition->value_end) || $obj_Condition->value_end == ""))
					{
						break;
					}
					$obj_StartDate = null;

					if (!(empty($str_Value) || $str_Value == "" || $str_Value == "*"))
					{
						$obj_StartDate = cReaperResults::convert_Date($str_Value);

						if (!$obj_StartDate)
						{
							print("The Index Start Date you entered is invalid and will be ignored.<br/>");
							break;
						}
					}

					$obj_EndDate = null;
					if (isset($obj_Condition->value_end) && ($obj_Condition->value_end != "*"))
					{
						$obj_EndDate = cReaperResults::convert_Date(trim($obj_Condition->value_end));
						if (!$obj_EndDate)
						{
							print("The Index End Date you entered is invalid and will be ignored.<br/>");
							break;
						}
						$obj_EndDate->setTime(23, 59, 59);
					}
					$this->m_obj_Query->add_Query_Date(cReaper_Doc::C_STR_FIELD_INDEX_DATE, $obj_StartDate, $obj_EndDate);
					break;
				case cReaper_Doc::C_STR_FIELD_HARVEST_DATE . "_":
					if ((empty($str_Value) || $str_Value == "") && (empty($obj_Condition->value_end) || $obj_Condition->value_end == ""))
					{
						break;
					}
					$obj_StartDate = null;

					if (!(empty($str_Value) || $str_Value == "" || $str_Value == "*"))
					{
						$obj_StartDate = cReaperResults::convert_Date($str_Value);

						if (!$obj_StartDate)
						{
							print("The Harvest Start Date you entered is invalid and will be ignored.<br/>");
							break;
						}
					}

					$obj_EndDate = null;
					if (isset($obj_Condition->value_end) && ($obj_Condition->value_end != "*"))
					{
						$obj_EndDate = cReaperResults::convert_Date(trim($obj_Condition->value_end));
						if (!$obj_EndDate)
						{
							print("The Harvest End Date you entered is invalid and will be ignored.<br/>");
							break;
						}
						$obj_EndDate->setTime(23, 59, 59);
					}
					$this->m_obj_Query->add_Query_Date(cReaper_Doc::C_STR_FIELD_HARVEST_DATE, $obj_StartDate, $obj_EndDate);
					break;
				case 'page':
				case 'perpage':
					break;
				default:
					if (empty($str_Value) || $str_Value == "")
					{
						break;
					}
					$this->m_obj_Query->add_Query($str_Value, $str_Key, $str_Join);
					break;
			}
		}

		public function create_Doc($obj_Data = null, $obj_Highlighting = null)
		{
			return new Reaper_Article($obj_Data, $obj_Highlighting);
		}
	}
